1 package net.sourceforge.selfesteem.test;
2
3 import junit.framework.TestCase;
4 import net.sourceforge.selfesteem.*;
5
6 public class CompositeNodeTest extends TestCase {
7 private TestNode _testA = new TestNode("foo/test a", true, 0.0);
8 private TestNode _testB = new TestNode("foo/test b", false, 0.0);
9
10 public CompositeNodeTest(String s) {
11 super(s);
12 }
13
14 public void testEmptyStory() {
15 StoryNode story = new StoryNode("story 1");
16 assertEquals("story 1", story.getName());
17 assertTrue(!story.isPassing());
18 assertEquals("story 1 - (0 / 0 tests passed - 0%)", story.toString());
19 }
20
21 public void testStoryNode() {
22 StoryNode story = new StoryNode("story 1");
23
24 story.add(_testA);
25 assertTrue(story.isPassing());
26
27 story.add(_testB);
28 assertTrue(!story.isPassing());
29
30 assertEquals(_testA, story.get(0));
31 assertEquals(_testB, story.get(1));
32 }
33
34 public void testIterationNode() {
35 IterationNode iteration = new IterationNode("iteration 1");
36
37 StoryNode story = new StoryNode("story1");
38 story.add(_testA);
39 iteration.add(story);
40 assertTrue(iteration.isPassing());
41
42 story.add(_testB);
43 assertTrue(!iteration.isPassing());
44 }
45
46 public void testStoryToString() {
47 StoryNode story = new StoryNode("foo");
48 story.add(new TestNode("foo/bar", true, 0.0));
49 story.add(new TestNode("foo/bar", false, 0.0));
50 story.add(new TestNode("foo/bar", true, 0.0));
51
52 assertEquals("foo - (2 / 3 tests passed - 66%)", story.toString());
53 }
54
55 public void testIterationToString() {
56 IterationNode iteration = new IterationNode("foo");
57 iteration.add(new TestNode("foo/bar", true, 0.0));
58 iteration.add(new TestNode("foo/bar", false, 0.0));
59 iteration.add(new TestNode("foo/bar", true, 0.0));
60
61 assertEquals("foo - (2 / 3 stories passed - 66%)", iteration.toString());
62 }
63
64 public void testRootToString() {
65 RootNode root = buildComplexGraph();
66
67 assertEquals("Acceptance Tests : 1 of 2 stories complete - 4 of 5 tests passing - 50%", root.toString());
68 }
69
70 public void testWrite() {
71 RootNode root = buildComplexGraph();
72
73 class TestSerializer extends Serializer {
74 private StringBuffer buffer = new StringBuffer();
75
76 protected void addLine(String line) {
77 buffer.append(line).append('\n');
78 }
79 }
80 ;
81 TestSerializer serializer = new TestSerializer();
82 root.serialize(serializer, 0);
83
84 assertEquals("Acceptance Tests : 1 of 2 stories complete - 4 of 5 tests passing - 50%\n" +
85 "-foo - (0 / 1 stories passed - 0%)\n" +
86 "--foo - (2 / 3 tests passed - 66%)\n" +
87 "---Passing Tests\n" +
88 "----bar\n" +
89 "----bar\n" +
90 "---Failing Tests\n" +
91 "----bar - null\n" +
92 "-foo - (1 / 1 stories passed - 100%)\n" +
93 "--foo - (2 / 2 tests passed - 100%)\n" +
94 "---Passing Tests\n" +
95 "----bar\n" +
96 "----bar\n",
97 serializer.buffer.toString());
98 }
99
100 private RootNode buildComplexGraph() {
101 RootNode root = new RootNode();
102 IterationNode iteration = new IterationNode("foo");
103 StoryNode story = new StoryNode("foo");
104 story.add(new TestNode("foo/bar", true, 0.0));
105 story.add(new TestNode("foo/bar", false, 0.0));
106 story.add(new TestNode("foo/bar", true, 0.0));
107 iteration.add(story);
108 root.add(iteration);
109
110 IterationNode iteration2 = new IterationNode("foo");
111 StoryNode story2 = new StoryNode("foo");
112 story2.add(new TestNode("foo/bar", true, 0.0));
113 story2.add(new TestNode("foo/bar", true, 0.0));
114 iteration2.add(story2);
115 root.add(iteration2);
116 return root;
117 }
118 }
This page was automatically generated by Maven